﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using FarseerGames.FarseerPhysics.Mathematics;
using FreeGoo.GameEngine;
using FreeGoo.GameEngine.Renderables;
using FreeGoo.GameEngine.Renderables.Particles;

namespace FreeGoo.LevelClasses.LevelParts
{
    public class CircleLevelPart : BodyRenderableLevelPart
    {
        public override string Name { get { return "Circle"; } }

        public override BodyRenderable BuildBodyRenderable(Level level, XElement element)
        {
            /* Example Xml:
             * <Circle Position="100.20,100.50" Radius="55.2" IsStatic="true">
             *   <Surface IsDeadly="true"/>
             * </Rectangle>
             */

            BodyRenderable circle;
            Vector2 position = GetOffsetPosition(level, element);
            float radius = element.Attribute("Radius").ToFloat(150);
            float angle = ConvertDegreesToRadians(element.Attribute("Rotation").ToFloat());
            int edges = element.Attribute("Edges").ToInt(MixedFactory.DefaultCircleEdges);
            float density = element.Attribute("Density").ToFloat(100.0f) / 100.0f;

            circle = MixedFactory.CreateCircle(
                level.Engine,
                position,
                radius,
                density,
                angle,
                edges);

            return circle;
        }
    }
}
